package org.lan.tree;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/11/25 9:27 AM
 */
public class TreeNode {
    public int val;

    public TreeNode left;

    public TreeNode right;

    public TreeNode(int val) {
        this.val = val;
    }

    public boolean isLeaf() {
        return left == null && right == null;
    }

    public void print() {
        Deque<TreeNode> deque = new ArrayDeque<>();
        deque.push(this);
        while (!deque.isEmpty()) {
            TreeNode node = deque.pop();
            System.out.println(node.val);
            if (node.left != null) {
                deque.add(node.left);
            }
            if (node.right != null) {
                deque.add(node.right);
            }
        }
    }

}
